package com.ellison.demo.example;

import lombok.extern.slf4j.Slf4j;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * Predicate接口
 * Predicate 接口只有一个参数，返回boolean类型。该接口包含多种默认方法来将Predicate组合成其他复杂的逻辑（比如：与，或，非）：
 *
 * @author Ellison_Pei
 * @date 2021/10/25 11:26
 * @since 1.0
 **/
@Slf4j
public class PredicateTest {

    public static void main(String[] args) {
        Predicate<String> predicate = (s) -> s.length() > 6;
        boolean result = predicate.test("foo");
        boolean result1 = predicate.negate().test("foo");
        Predicate<Boolean> nonNull = Objects::nonNull;
        Predicate<Boolean> isNull = Objects::isNull;
        Predicate<String> isEmpty = String::isEmpty;
        Predicate<String> isNotEmpty = isEmpty.negate();
        log.debug("{}", result);
        log.debug("{}", result1);
    }
}
